﻿#region 命名空间

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Sharp.Domain.PlatformBoundedContext.MessageModule.Aggregates;
using Sharp.Domain.PlatformBoundedContext.OrgModule.Aggregates;
using Sharp.Domain.PlatformBoundedContext.PermissionModule.Aggregates;
using Sharp.Domain.PlatformBoundedContext.PersonModule.Aggregates;
using Sharp.Domain.Model;
using Sharp.Infrastructure;

#endregion

namespace Sharp.Domain.PlatformBoundedContext.UserModule.Aggregates
{
    /// <summary>
    ///     用户
    /// </summary>
    public partial class User : IAggregateRoot<int>, ILogCreatedEntity, ILogModifiEntity, IStandardState
    {
        public User()
        {
            Roles = new List<Role>();
            Groups = new List<Group>();
            Permissions = new List<Permission>();
        }
        [Key]
        public int Id { get; set; }

        /// <summary>
        ///     获取或设置当前客户的用户名。
        /// </summary>
        [Index]
        public string UserName { get; set; }

        /// <summary>
        ///     获取或设置当前客户的登录密码。
        /// </summary>
        public string Password { get; set; }

        /// <summary>
        ///     获取或设置当前客户的电子邮件地址。
        /// </summary>
        [Index]
        public string Email { get; set; }
        /// <summary>
        /// 头像
        /// </summary>
        [NonUnicode, StringLength(255)]
        public string Face { get; set; }
        /// <summary>
        /// 手机号码
        /// </summary>
        [NonUnicode]
        public string PhoneNember { get; set; }

        [DefaultValue(1), Index("IX_EntityStateCreatedUserId", 0)]
        public EntityStateOperate EntityState { get; set; }
        /// <summary>
        ///     获取或设置用户账户最后一次登录的时间。
        /// </summary>
        public DateTime? LastLogonTime { get; set; }
        /// <summary>
        /// 获取或设置用户最后一次登录的IP
        /// </summary>
        public string LastLogonIp { get; set; }

        /// <summary>
        /// 添加日期
        /// </summary>
        /// <value>添加日期</value>
        public System.DateTime? CreatedTime { get; set; }
        /// <summary>
        /// 录入员的id
        /// </summary>
        /// <value>录入员的id</value>
        [Index("IX_EntityStateCreatedUserId", 1)]
        public int? CreatedUserId { get; set; }
        /// <summary>
        /// 修改时间
        /// </summary>
        /// <value>修改时间</value>
        public System.DateTime? ModifiTime { get; set; }
        /// <summary>
        /// 修改数据的用户Id
        /// </summary>
        /// <value>修改数据的用户Id</value>
        public int? ModifiedUserId { get; set; }

        /// <summary>
        /// 用户的扩展资料
        /// </summary>
        [ForeignKey("Id")]
        public virtual UserProfile Profile { get; set; }

        /// <summary>
        /// 人员扩展资料
        /// </summary>
        [ForeignKey("Id")]
        public virtual Person Person { get; set; }

        /// <summary>
        ///     角色
        /// </summary>
        public virtual ICollection<Role> Roles { get; set; }

        /// <summary>
        ///     用户权限
        /// </summary>
        public virtual ICollection<Permission> Permissions { get; set; }

        #region ToString方法

        /// <summary>
        ///     返回表示当前Object的字符串。
        /// </summary>
        /// <returns>表示当前对象的字符串。</returns>
        public override string ToString()
        {
            return UserName;
        }

        #endregion


        /// <summary>
        /// 已授权组织
        /// </summary>
        public virtual ICollection<Org> AuthorizedOrgs { get; set; }

        /// <summary>
        /// 工作组
        /// </summary>
        public virtual ICollection<Group> Groups { get; set; }
    }
}